﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.master" AutoEventWireup="true"
    CodeFile="PostEdit.aspx.cs" Inherits="Admin_Modules_Posts_PostEdit" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Src="Controls/Tags.ascx" TagName="Tags" TagPrefix="uc1" %>
<%@ Register Src="Controls/CategoryList.ascx" TagName="CategoryList" TagPrefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script src="/js/Editor.js"></script>
    <script src="/js/jquery.js"></script>
    <script src="../../js/datetimepicker.js"></script>
    <link href="/css/Dialog.css" rel="stylesheet" />
    <link href="/css/Editor.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="c" runat="Server">
    <div id="wpbody-content" style="overflow: hidden;">
        <div id="screen-meta">
            <div class="wrap">
                <div id="icon-edit" class="icon32 icon32-posts-post">
                    <br />
                </div>
                <h2>Add New Post</h2>
                <div id="poststuff" class="metabox-holder has-right-sidebar">
                    <div id="side-info-column" class="inner-sidebar">
                        <div id="side-sortables" class="meta-box-sortables ui-sortable">
                            <%--<input type="submit" accesskey="p" tabindex="5" value="Publish" class="button-primary" id="publish" name="publish" />
                            <input type="submit" class="button button-highlighted" tabindex="4" value="Save Draft" id="save-post" name="save">--%>
                            <div id="postimagediv" class="postbox ">
                                <div class="handlediv" title="Click to toggle">
                                    <br />
                                </div>
                                <h3 class="hndle">
                                    <span>Featured Image</span></h3>
                                <div class="inside">
                                    <div style="width: 80px; height: 80px; border: solid thin orange;">
                                        <asp:Image ID="imgThumb" runat="server" EnableViewState="true" AlternateText="Ảnh đại diện"
                                            ToolTip="Ảnh đại diện tour" Width="80px" Height="80px" />
                                        <asp:HiddenField ID="hdfimg" runat="server" />
                                    </div>
                                    <div>
                                        <telerik:DialogOpener runat="server" ID="DialogOpener1"></telerik:DialogOpener>
                                        <input type="button" id="btnSelectThumb" value="Chọn" style="width: 40px;" onclick="selectThumb()" />
                                        <input type="button" id="btnClearThumb" value="Xóa" style="width: 40px;" onclick="clearThumb()" />
                                    </div>
                                </div>
                            </div>
                            <div id="submitdiv" class="postbox ">
                                <div class="handlediv" title="Click to toggle">
                                    <br />
                                </div>
                                <h3 class="hndle">
                                    <span>Publish</span></h3>
                                <div class="inside">

                                    <asp:DropDownList ID="ddlpublish" runat="server">
                                        <asp:ListItem Text="Draft" Value="draft"></asp:ListItem>
                                        <asp:ListItem Text="Publish" Value="publish"></asp:ListItem>
                                        <asp:ListItem Text="Lock" Value="lock"></asp:ListItem>
                                    </asp:DropDownList>
                                    <asp:TextBox ID="txtPublishDate" MaxLength="25" runat="server"></asp:TextBox>
                                    <a href="javascript:NewCal('<%=txtPublishDate.ClientID %>','ddMMyyyy','dropdown',true,'12',true)">
                                        <img src="../../images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
                                    <asp:Button ID="btnSave" runat="server" CssClass="button button-highlighted" Text=" Save "
                                        OnClick="btnSave_Click" />
                                    <asp:CheckBox ID="chbChangeDateTime" runat="server" Text="Thay đổi ngày tạo" />
                                </div>
                            </div>
                            <div id="Div1" class="postbox ">
                                <div class="handlediv" title="Click to toggle">
                                    <br />
                                </div>
                                <h3 class="hndle">
                                    <span>Author</span></h3>
                                <div class="inside">
                                    <asp:DropDownList ID="ddlAuthor" runat="server">
                                    </asp:DropDownList>
                                </div>
                            </div>
                            <div id="categorydiv" class="postbox ">
                                <div class="handlediv" title="Click to toggle">
                                    <br />
                                </div>
                                <h3 class="hndle">
                                    <span>Categories</span></h3>
                                <div class="inside">
                                    <div id="taxonomy-category" class="categorydiv">
                                        <ul id="category-tabs" class="category-tabs">
                                            <li class="tabs"><a href="#category-all" tabindex="3">All Categories</a></li>
                                        </ul>
                                        <div id="category-all" class="tabs-panel" style="height: 300px;">
                                            <uc2:CategoryList ID="CategoryList1" runat="server" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="post-body">
                        <div id="post-body-content">
                            <div id="titlediv">
                                <div id="titlewrap">
                                    <label style="color: #BBBBBB; font-size: 1.2em;" id="Label2" for="title">
                                        Title</label><br />
                                    <asp:TextBox ID="txtTitle" runat="server" CssClass="title" Width="700"></asp:TextBox>
                                </div>
                                <div id="Div2">
                                    <label style="color: #BBBBBB; font-size: 1.2em;" id="Label1" for="txtSummary">
                                        Summary</label><br />
                                    <asp:TextBox ID="txtSummary" runat="server" CssClass="title" TextMode="MultiLine"
                                        Width="700" Height="100">
                                    </asp:TextBox>
                                </div>
                            </div>
                        </div>
                        <div id="postdivrich" class="postarea">
                            <asp:ScriptManager ID="ScriptManager1" runat="server" />
                            <label style="color: #BBBBBB; font-size: 1.2em;" id="Label3" for="radEditorContent">
                                Content</label><br />
                            <telerik:RadEditor Width="700" Height="530" ID="radEditorContent" ToolsFile="~/App_Data/Xml/DefaultToolbar.xml"
                                runat="server" Skin="Default" EditModes="All" NewLineBr="false" EnableEmbeddedScripts="true"
                                StripFormattingOptions="Css,Font,Span,MSWord,MSWordNoFonts,MSWordRemoveAll" StripFormattingOnPaste="Css,Font,Span,MSWord,MSWordNoFonts,MSWordRemoveAll"
                                ToolbarMode="Default" OnClientPasteHtml="OnClientPasteHtml1" OnClientCommandExecuted="OnClientCommandExecuted"
                                SpellCheckSettings-AllowAddCustom="false" EnableResize="false" ContentFilters="ConvertToXhtml, RemoveScripts,FixUlBoldItalic, IECleanAnchors, FixEnclosingP, MozEmStrong,IndentHTMLContent, OptimizeSpans">
                                <CssFiles>
                                    <telerik:EditorCssFile Value="/css/Editor.css" />
                                </CssFiles>
                                <TemplateManager ViewPaths="/Uploads/Templates" UploadPaths="/Uploads/Templates"
                                    DeletePaths="/Uploads/Templates" />
                                <SpellCheckSettings AllowAddCustom="False"></SpellCheckSettings>
                                <ContextMenus>
                                    <telerik:EditorContextMenu TagName="P">
                                        <telerik:EditorTool Name="CustomApplyCSS_Title" ShowIcon="false" Text="pTitle" />
                                        <telerik:EditorTool Name="CustomApplyCSS_Head" ShowIcon="false" Text="pHead" />
                                        <telerik:EditorTool Name="CustomApplyCSS_Body" ShowIcon="false" Text="pBody" />
                                        <telerik:EditorTool Name="CustomApplyCSS_InterTitle" ShowIcon="false" Text="pInterTitle" />
                                        <telerik:EditorTool Name="CustomApplyCSS_SubTitle" ShowIcon="false" Text="pSubTitle" />
                                        <telerik:EditorTool Name="CustomApplyCSS_Caption" ShowIcon="false" Text="pCaption" />
                                        <telerik:EditorTool Name="CustomApplyCSS_Question" ShowIcon="false" Text="pQuestion" />
                                        <telerik:EditorTool Name="CustomApplyCSS_Author" ShowIcon="false" Text="pAuthor" />
                                        <telerik:EditorTool Name="CustomApplyCSS_Source" ShowIcon="false" Text="pSource" />
                                    </telerik:EditorContextMenu>
                                </ContextMenus>
                                <Content></Content>
                            </telerik:RadEditor>
                            <script language="javascript" type="text/javascript">
                                var regexWhiteSpace = new RegExp("<(p[^>]*)>(((\&nbsp;)*\s*)*)?</p>|<(p[^>]*)><(span[^>]*)>(((\&nbsp;)*\s*)*)?</span></p>|<(font[^>]*)>|<(/font[^>]*)>|<o:p>|</o:p>|<(st1[^>]*)>|<(/st1[^>]*)>|&nbsp;", "gi");
                                var regexP = new RegExp("(<p|<P)[^>]*>(.*?)(<\/P>|<\/p>)", "gi");
                                var regexOpenDIV = new RegExp("(<div|<DIV)[^>]*>", "gi");
                                var regexCloseDIV = new RegExp("(<\/DIV>|<\/div>)", "gi");
                                /*var regexSpan = new RegExp("(<span[^*>]*>)|(<\/span>)|(<SPAN[^*>]*>)|(<\/SPAN>)", "gi");*/
                                var regexSpan = new RegExp("(<span|<SPAN)[^>]*>(.*?)(<\/SPAN>|<\/span>)", "gi");
                                /*var regexFont = new RegExp("(<font[^*>]*>)|(<\/font>)|(<FONT[^*>]*>)|(<\/FONT>)", "gi");*/
                                var regexFont = new RegExp("(<font|<FONT)[^>]*>(.*?)(<\/FONT>|<\/font>)", "gi");
                                var regexStrong = new RegExp("(<strong[^*>]*>)|(<\/strong>)|(<STRONG[^*>]*>)|(<\/STRONG>)", "gi");
                                var regexB = new RegExp("(<b|<B)[^>]*>(.*?)(<\/B>|<\/b>)", "gi");
                                var regexU = new RegExp("(<u|<U)[^>]*>(.*?)(<\/U>|<\/u>)", "gi");
                                var regexI = new RegExp("(<i|<I)[^>]*>(.*?)(<\/I>|<\/i>)", "gi");
                                var regexTABLE = new RegExp("(<table|<TABLE)[^>]*>(.*?)(<\/TABLE>|<\/table>)", "gi");
                                var regexH1 = new RegExp("(<h1|<H1)[^>]*>(.*?)(<\/H1>|<\/h1>)", "gi");
                                var regexH2 = new RegExp("(<h2|<H2)[^>]*>(.*?)(<\/H2>|<\/h2>)", "gi");
                                var regexEM = new RegExp("(<em|<EM)[^>]*>(.*?)(<\/EM>|<\/em>)", "gi");
                                var regexA = new RegExp("(<a|<A)[^>]*>(.*?)(<\/A>|<\/a>)", "gi");
                                var regexUL = new RegExp("(<ul|<UL)[^>]*>(.*?)(<\/UL>|<\/ul>)", "gi");
                                var regexBlockquote = new RegExp("(<blockquote|<BLOCKQUOTE)[^>]*>(.*?)(<\/BLOCKQUOTE>|<\/blockquote>)", "gi");

                                function OnClientPasteHtml1(editor, args) {
                                    var commandName = args.get_commandName();
                                    var value = args.get_value();

                                    if (commandName == "Paste") {
                                        var pasteContent = value;
                                        pasteContent = pasteContent.replace(regexOpenDIV, "<P class=pBody>");
                                        pasteContent = pasteContent.replace(regexCloseDIV, "</P>");
                                        pasteContent = pasteContent.replace(regexP, "<P class=pBody>$2</P>").replace(regexWhiteSpace, " ");
                                        pasteContent = pasteContent.replace(regexSpan, "<P class=pBody>$2</P>");
                                        /*pasteContent = pasteContent.replace(regexFont, "");*/
                                        pasteContent = pasteContent.replace(regexFont, "$2");
                                        pasteContent = pasteContent.replace(regexStrong, "");
                                        pasteContent = pasteContent.replace(regexB, "$2");
                                        pasteContent = pasteContent.replace(regexU, "$2");
                                        pasteContent = pasteContent.replace(regexI, "$2");
                                        pasteContent = pasteContent.replace(regexTABLE, "");
                                        pasteContent = pasteContent.replace(regexH1, "<P class=pBody>$2</P>");
                                        pasteContent = pasteContent.replace(regexH2, "<P class=pBody>$2</P>");
                                        pasteContent = pasteContent.replace(regexEM, "$2");
                                        pasteContent = pasteContent.replace(regexA, "$2");
                                        pasteContent = pasteContent.replace(regexUL, "<P class=\'pBody\'>$2</P>").replace(regexWhiteSpace, " ");
                                        pasteContent = pasteContent.replace(regexBlockquote, "<P class=\'pBody\'>$2</P>").replace(regexWhiteSpace, " ");
                                        pasteContent = pasteContent.replace(/size|SIZE = ([\d]{1})/g, '');

                                        //set the modified pasted content in the editor
                                        args.set_value(pasteContent);
                                    }
                                }

                                function OnClientCommandExecuted(editor, args) {
                                    if ("ApplyClass" == args.get_commandName()) {
                                        var content = editor.get_html(true);
                                        content = content.replace(/span/gi, "p");
                                        editor.set_html(content);
                                    }
                                }

                                // Insert Image From List Into Editor Content
                                Telerik.Web.UI.Editor.CommandList["CustomImageManager"] = function (commandName, radEditorContent, args) {
                                    var insertImageCallbackFunction = function (sender, args) {
                                        if (!args.IsCancel) {
                                            var html = GetImageAttribute(args);
                                            radEditorContent.pasteHtml(html);
                                        }
                                    };
                                    // Indent
                                    Telerik.Web.UI.Editor.CommandList["CustomerIndent"] = function (commandName, editor, args) {
                                        editor.pasteHtml('<span style="width:200px;border: 1px dashed #bb0000;background-color: #fafafa;color: blue;"> ' + args.get_value() + ' </span>');
                                    };

                                    radEditorContent.showExternalDialog(
                                    '' + '/Admin/Modules/FileManager/InsertFTPImage.aspx', {},
                                    800, 620, insertImageCallbackFunction, null, null, true,
                                    Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move, false, true);
                                };

                                // Insert Document From List Into Editor Content
                                Telerik.Web.UI.Editor.CommandList["CustomDocumentManager"] = function (commandName, radEditorContent, args) {

                                    var argument = radEditorContent.getSelectionHtml();
                                    var insertDocumentCallbackFunction = function (sender, args) {
                                        if (!args.IsCancel) {
                                            var html = GetDocumentAttribute(args);
                                            radEditorContent.pasteHtml(html);
                                        }
                                    };

                                    radEditorContent.showExternalDialog(
                                '' + '/Admin/Modules/FileManager/InsertFTPDocument.aspx', argument,
                                780, 550, insertDocumentCallbackFunction, null, null, true,
                                Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move, false, true);
                                };

                                // Flash Video
                                Telerik.Web.UI.Editor.CommandList["CustomVideoManager"] = function (commandName, radEditorContent, args) {
                                    var insertVideoCallbackFunction = function (sender, args) {
                                        if (!args.IsCancel) {
                                            var html = GetVideoAttribute(args);
                                            radEditorContent.pasteHtml(html);
                                        }
                                    }

                                    radEditorContent.showExternalDialog(
                                    '' + '/Admin/Modules/FileManager/InsertVideo.aspx', {},
                                    800, 620, insertVideoCallbackFunction, null, null, true,
                                    Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move, false, true);
                                };

                                // Insert Custom Audio
                                Telerik.Web.UI.Editor.CommandList["CustomAudioManager"] = function (commandName, radEditorContent, args) {
                                    var insertAudioCallbackFunction = function (sender, args) {
                                        if (!args.IsCancel) {
                                            var html = GetAudioAttribute(args);
                                            radEditorContent.pasteHtml(html);
                                        }
                                    }

                                    radEditorContent.showExternalDialog(
                                    '' + '/Admin/Modules/FileManager/InsertAudio.aspx',
                                    {},
                                    800,
                                    620,
                                    insertAudioCallbackFunction,
                                    null,
                                    null,
                                    true,
                                    Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move,
                                    false,
                                    true);

                                };



                                function selectThumb() {
                                    var radEditorContent = $find("<%= DialogOpener1.ClientID %>");
                                    radEditorContent.openUrl("/Admin/Modules/FileManager/InsertFTPImage.aspx", {}, 800, 600, selectThumbComplete, null, "custom link manager", true);
                                }

                                function clearThumb() {
                                    $('#<%= imgThumb.ClientID %>').attr("scr", "");
                                    $('#<%= hdfimg.ClientID %>').val("");
                                }
                                var selectThumbComplete = function (sender, args) {
                                    if (!args.IsCancel) {
                                        if (args.Url.length > 0) {
                                            var img = document.getElementById("<%= imgThumb.ClientID %>");
                                            img.src = args.Url;
                                            $('#<%= hdfimg.ClientID %>').val(args.Url);
                                            // alert($('#<%= hdfimg.ClientID %>').val());

                                        }
                                    }
                                }
                            </script>
                            <script language="javascript" type="text/javascript">
                                // App Style for Paragraph
                                Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Title"] = function (commandName, radEditorContent, args) {
                                    var objPara = radEditorContent.getSelectedElement();
                                    objPara.className = 'pTitle';
                                };

                                Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Head"] = function (commandName, radEditorContent, args) {
                                    var objPara = radEditorContent.getSelectedElement();
                                    objPara.className = 'pHead';
                                };

                                Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Body"] = function (commandName, radEditorContent, args) {
                                    var objPara = radEditorContent.getSelectedElement();
                                    objPara.className = 'pBody';
                                };

                                Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_InterTitle"] = function (commandName, radEditorContent, args) {
                                    var objPara = radEditorContent.getSelectedElement();
                                    objPara.className = 'pInterTitle';
                                };

                                Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_SubTitle"] = function (commandName, radEditorContent, args) {
                                    var objPara = radEditorContent.getSelectedElement();
                                    objPara.className = 'pSubTitle';
                                };

                                Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Caption"] = function (commandName, radEditorContent, args) {
                                    var objPara = radEditorContent.getSelectedElement();
                                    objPara.className = 'pCaption';
                                };

                                Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Question"] = function (commandName, radEditorContent, args) {
                                    var objPara = radEditorContent.getSelectedElement();
                                    objPara.className = 'pQuestion';
                                };

                                Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Author"] = function (commandName, radEditorContent, args) {
                                    var objPara = radEditorContent.getSelectedElement();
                                    objPara.className = 'pAuthor';
                                };

                                Telerik.Web.UI.Editor.CommandList["CustomApplyCSS_Source"] = function (commandName, radEditorContent, args) {
                                    var objPara = radEditorContent.getSelectedElement();
                                    objPara.className = 'pSource';
                                };
                            </script>
                            <br />
                            <div id="tagsdiv">
                                <label style="color: #BBBBBB; font-size: 1.2em;" id="Label4" for="title">
                                    Tags(???,???,???...)</label><br />
                                <asp:TextBox ID="txtTag" runat="server" CssClass="text_tags" Width="700"></asp:TextBox>
                            </div>
                            <div class="icon32 icon32-posts-post icon-post">
                                <br />
                            </div>
                            <h2>SEO</h2>
                            <div>
                                <label style="color: #BBBBBB; font-size: 1.2em;" id="Label5" for="title">
                                    Title
                                </label>
                                <br />
                                <asp:TextBox ID="txtSEOTitle" runat="server" CssClass="text_tags" Width="700"></asp:TextBox>
                            </div>
                            <div>
                                <label style="color: #BBBBBB; font-size: 1.2em;" id="Label6" for="title">
                                    KeyWord</label><br />
                                <asp:TextBox ID="txtSEOKeyWord" runat="server" CssClass="text_tags" TextMode="MultiLine"
                                    Width="700" Height="50">
                                </asp:TextBox>
                            </div>
                            <div>
                                <label style="color: #BBBBBB; font-size: 1.2em;" id="Label7" for="title">
                                    Description</label><br />
                                <asp:TextBox ID="txtSEODescription" runat="server" CssClass="text_tags" TextMode="MultiLine"
                                    Width="700" Height="50">
                                </asp:TextBox>
                            </div>
                        </div>
                    </div>
                    <br class="clear" />
                </div>
                <!-- /poststuff -->
            </div>
            <div class="clear">
            </div>
        </div>
    </div>
</asp:Content>
